<?php

	/* load config file */

	function loadConfig($path)
	{
		global $_config;
		
		$configFile = file($path."data/config.cfg");

		if (is_array($configFile)) {

			foreach ($configFile as $line) {

				$line = trim($line);

				if ($line != "" AND strpos($line, "=") !== false AND substr($line, 0, 1) != "#") {

					$lineData = explode("=", $line);

					$key = strtolower(trim($lineData[0]));
					$value = trim($lineData[1]);

						if (strtolower($value) == "false" OR strtolower($value) == "no") {
							$value = false;
						} elseif (strtolower($value) == "true" OR strtolower($value) == "yes") {
							$value = true;
						}

					$_config[$key] = $value;

				}

			}
			
			$_config['root'] = substr($_SERVER['DOCUMENT_ROOT'], 0, -1);

			$_config['root'] = substr($_config['root'], 0, strrpos($_config['root'], '/')+1);

			$_config['root'] = str_replace("htdocs/", "", $_config['root']);


		} else error("Fehler beim Auslesen der Konfigurationsdatei");
		
	}
	
	
	/* get config variable */
	
	function config($key)
	{
		global $_config;
		
		if (isset($_config[strtolower($key)])) {
			return $_config[strtolower($key)];
		} else die("Konfigurationsvariable '".$key."' nicht gefunden");
		
	}

?>
